package com.hyp.mapper;

import com.hyp.pojo.Favorites;
import com.hyp.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FavoritesMapper {
    @Select("SELECT * FROM Favorites WHERE UserID = #{userId} AND ProductID = #{productId}")
    Favorites findByUserIdAndProductId(@Param("userId") Integer userId, @Param("productId") Integer productId);

    @Insert("INSERT INTO Favorites (UserID, ProductID, CreatedAt) VALUES (#{userId}, #{productId}, #{createdAt})")
    void insert(Favorites favorites);

    @Delete("DELETE FROM Favorites WHERE FavoriteID = #{id}")
    void deleteById(Integer id);

    @Select("SELECT p.* FROM Favorites f JOIN Product p ON f.ProductID = p.ProductID WHERE f.UserID = #{userId}  order by f.createdAt DESC;")
    List<Product> favoriteList(Integer userId);
}
